#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
创建简单的图标集
为SQL编辑器按钮生成基本图标
"""

import os
from PIL import Image, ImageDraw, ImageFont
import io

# 确保目录存在
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), 'resources')
os.makedirs(RESOURCES_DIR, exist_ok=True)

def create_icon(name, color, size=(32, 32), bg_color=(255, 255, 255, 0)):
    """创建简单的方形图标
    
    Args:
        name: 图标名称
        color: 图标颜色 (R, G, B)
        size: 图标尺寸
        bg_color: 背景颜色
    """
    img = Image.new('RGBA', size, bg_color)
    draw = ImageDraw.Draw(img)
    
    # 图标设计
    if name == 'run':
        # 播放三角形
        points = [(8, 8), (24, 16), (8, 24)]
        draw.polygon(points, fill=color)
    elif name == 'stop':
        # 停止方块
        draw.rectangle([8, 8, 24, 24], fill=color)
    elif name == 'format':
        # 格式化图标 (排列的线条)
        for i in range(3):
            y = 10 + i * 6
            draw.line([(8, y), (18 + i*4, y)], fill=color, width=2)
    elif name == 'clear':
        # 清除图标 (叉)
        draw.line([(8, 8), (24, 24)], fill=color, width=2)
        draw.line([(24, 8), (8, 24)], fill=color, width=2)
    elif name == 'search':
        # 搜索图标 (放大镜)
        draw.ellipse([8, 8, 20, 20], outline=color, width=2)
        draw.line([(18, 18), (24, 24)], fill=color, width=2)
    elif name == 'comment':
        # 注释图标 (双斜线)
        draw.line([(10, 10), (16, 22)], fill=color, width=2)
        draw.line([(14, 10), (20, 22)], fill=color, width=2)
    elif name == 'fold':
        # 折叠图标 (三角形)
        points = [(12, 8), (20, 8), (16, 16)]
        draw.polygon(points, fill=color)
        draw.line([(8, 20), (24, 20)], fill=color, width=2)
    elif name == 'indent':
        # 缩进图标 (对齐线)
        draw.line([(8, 10), (24, 10)], fill=color, width=2)
        draw.line([(12, 16), (24, 16)], fill=color, width=2)
        draw.line([(8, 22), (24, 22)], fill=color, width=2)
    elif name == 'snippet':
        # 代码片段图标 (花括号)
        draw.line([(10, 8), (14, 8), (14, 24), (10, 24)], fill=color, width=2)
        draw.line([(22, 8), (18, 8), (18, 24), (22, 24)], fill=color, width=2)
    
    # 保存图标
    filepath = os.path.join(RESOURCES_DIR, f"{name}.png")
    img.save(filepath)
    print(f"创建图标: {filepath}")

# 创建图标集
icons = [
    ('run', (76, 175, 80)),       # 绿色
    ('stop', (244, 67, 54)),      # 红色
    ('format', (33, 150, 243)),   # 蓝色
    ('clear', (96, 125, 139)),    # 灰色
    ('search', (156, 39, 176)),   # 紫色
    ('comment', (121, 85, 72)),   # 棕色
    ('fold', (255, 152, 0)),      # 橙色
    ('indent', (3, 169, 244)),    # 浅蓝色
    ('snippet', (63, 81, 181))    # 靛蓝色
]

if __name__ == "__main__":
    for name, color in icons:
        create_icon(name, color)
    print("所有图标创建完成") 